﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;

namespace eCommerce.db.SQLDataAccess
{
    public static class DbCommon
    {
        #region properties

        private static string _connectionString = string.Empty;
        private static string _databaseSchema = "[dbo].";

        /// <summary>
        /// Gets or sets string value for ConnectionString property
        /// </summary>
        public static string ConnectionString
        {
            get { return _connectionString; }
            set { _connectionString = value; }
        }

        public static string DatabaseSchema
        {
            get { return _databaseSchema; }
            set { _databaseSchema = value; }
        }

        #endregion

        public static SqlParameter AddParameter(SqlCommand cmd, string parameterName, object parameterValue)
        {
            parameterName = "@" + parameterName;
            return cmd.Parameters.AddWithValue(parameterName, parameterValue);
        }

        public static ParameterDirection SetParameterOut(SqlCommand cmd, string parameterName)
        {
            parameterName = "@" + parameterName;
            return (cmd.Parameters[parameterName].Direction = ParameterDirection.Output);
        }

        public static PropertyInfo GetPropertyInfo(object _object, string _propertyName)
        {
            foreach (PropertyInfo info in _object.GetType().GetProperties())
            {
                if (info.Name.Equals(_propertyName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return info;
                }
            }
            return null;
        }
    }
}
